#include "mainwindowimpl.h"
#include "logika.h"
#include "scaledplot.h"
#include <QFile>
#include <QFileDialog>
#include <QDataStream>
#include <QHBoxLayout>
#include <QDebug>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_histogram.h>
#include <qwt_series_data.h>
//
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f) 
	: QMainWindow(parent, f), l(new Logika(this)){
	setupUi(this);
}
//

void MainWindowImpl::on_OpenFileActn_triggered(){
	l->loadFromFile(QFileDialog::getOpenFileName(this, trUtf8("Выберите звуковой файл")));

	QHBoxLayout * layout = new QHBoxLayout(sourceGrpBx);
	QHBoxLayout * layout2 = new QHBoxLayout(rezGrpBx);
	QwtPlotCurve *curve;
	QwtPlotHistogram * histogram;
	ScaledPlot * sp;
	for(int i = 0; i < l->nChannels(); ++i){
		sp = new ScaledPlot(this);
		layout->addWidget(sp);
		curve = new QwtPlotCurve(trUtf8("Канал %1").arg(i));
		dc.append(new QwtPointSeriesData(l->getCurveChannel(i)));
		curve->setData(dc[i]);
		curve->attach(sp->qwtPlot());
		sp->replot();

		sp = new ScaledPlot(this);
		layout2->addWidget(sp);
		histogram = new QwtPlotHistogram(trUtf8("Канал %1").arg(i));
		dh.append(new QwtIntervalSeriesData(l->getCurveSpectrum(i)));
		histogram->setData(dh[i]);
//		sp->setHorizontalLength(p.size());
		histogram->attach(sp->qwtPlot());
		sp->replot();
	}
}
